package cn.chinaflame.pagodas.schedul;

import cn.chinaflame.pagodas.utils.ScheduleTime;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;


/**
 * 调度器
 *
 * @author wwt
 * @date 2018年1月17日 上午9:52:41
 */
public class PaOrderSchedule {
    private static ScheduledExecutorService Manager;
    private static PaOrderSchedule paOrderSchedule;

    static {
        Manager = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
    }

    private PaOrderSchedule() {

    }

    public synchronized static PaOrderSchedule getInstance() {
        if (paOrderSchedule == null) {
            paOrderSchedule = new PaOrderSchedule();
        }
        return paOrderSchedule;
    }

    /**
     * 预约订单时调用，一段时间后订单失效
     */
    public void startTask(Runnable task, ScheduleTime time) {
        Manager.schedule(task, time.getDelay(), time.getTime());
    }

}
